import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { EventName } from "../../mvc/EventName";
import { ObjCreate } from "../common/ObjCreate";
import { ImagesConst } from "../../resource/ImagesConst";
import { Language } from "../../../../extend/language/Language";
import { GTextFormat } from "../../../common/GTextFormat";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { QuickSellGoodsItem } from "./QuickSellGoodsItem";
import { DataEvent } from "../../events/DataEvent";
import { ItemData } from "../../resource/info/ItemData";
import { SSeqMarketItem } from "../../../../Message/Game/SSeqMarketItem";
import { SMarketItem } from "../../../../Message/Game/SMarketItem";
import { EPrictUnit } from "../../../../Message/Public/EPrictUnit";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
//class QuickSellGoodsPanel
    
    export  class QuickSellGoodsPanel /* flash.display.Sprite */
    {
        constructor()
        {
            
            this._quickSellItemArr = [];
            this.init();
            Dispatcher.addEventListener(EventName.BackPackClickToMarket, this.onBackPackClickToMarketHandler);
            return;
        }

        /* internal  */init(): void
        {
            var loc5=null;
            var loc1=ObjCreate.createBg(0, 0, 287, 298, this);
            ObjCreate.createBitmap(ImagesConst.Fire, 25, 20, this);
            var loc2=Language.getString(31081);
            var loc3=new GTextFormat("", 12, 65280, null, null, null, null, null, null, null, null, null, 5);
            var loc4;
            (loc4 = ObjCreate.createTextField(loc2, 25, 27, 240, 80, this, loc3)).multiline = true;
            loc4.wordWrap = true;
            ObjCreate.createBg(20, 95, 250, 2, this, ImagesConst.SplitLine);
            ObjCreate.createTextField(Language.getString(31082), 20, 110, 150, 20, this, GlobalStyle.textFormat2);
            ObjCreate.createTextField(Language.getString(31083), 20, 150, 150, 20, this, GlobalStyle.textFormat2);
            ObjCreate.createTextField(Language.getString(31084), 20, 185, 150, 40, this, GlobalStyle.textFormat2);
            ObjCreate.createTextField(Language.getString(31085), 20, 220, 80, 20, this, GlobalStyle.textFormat2);
            ObjCreate.createGTextField(Language.getString(31086), 20, 255, 80, 20, this, GlobalStyle.textFormat2);
            var loc6=140;
            var loc7=0;
            while (loc7 < 1) 
            {
                (loc5 = new QuickSellGoodsItem()).x = loc6;
                loc5.y = 100;
                addChild(loc5);
                loc5.addEventListener(EventName.MarketNumStepperChange, this.onNumStepperChangeHandler);
                this._quickSellItemArr.push(loc5);
                loc6 = loc6 + 80;
                ++loc7;
            }
            this._priceImg = new Object /* flash.display.Bitmap */();
            this._priceImg.x = 100;
            this._priceImg.y = 257;
            addChild(this._priceImg);
            var loc8=new GTextFormat("", 12, 268419072);
            this._allPriceTxt = ObjCreate.createTextField("", 120, 255, 80, 20, this, loc8);
            var loc9;
            (loc9 = ObjCreate.createGButton(Language.getString(31087), 70, 303, 60, 25, this)).addEventListener(flash.events.MouseEvent.CLICK, this.onSubmitBtnClickHandler);
            var loc10;
            (loc10 = ObjCreate.createGButton(Language.getString(31088), 160, 303, 60, 25, this)).addEventListener(flash.events.MouseEvent.CLICK, this.onResetBtnClickHandler);
            return;
        }

        /* internal  */onBackPackClickToMarketHandler(arg1: DataEvent): void
        {
            var loc2=null;
            var loc3=0;
            var loc1=arg1.data as ItemData;
            loc3 = 0;
            while (loc3 < this._quickSellItemArr.length) 
            {
                loc2 = this._quickSellItemArr[loc3] as QuickSellGoodsItem;
                if (loc2 && !loc2.isSearch) 
                {
                    loc2.setItemData(loc1);
                }
                ++loc3;
            }
            return;
        }

        /* internal  */onResetBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this.resetPanel();
            return;
        }

        /* internal  */onSubmitBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=null;
            var loc2=0;
            loc2 = 0;
            while (loc2 < this._quickSellItemArr.length) 
            {
                loc1 = this._quickSellItemArr[loc2] as QuickSellGoodsItem;
                loc1.sellGoods();
                ++loc2;
            }
            return;
        }

        public resetPanel(): void
        {
            var loc1=null;
            var loc2=0;
            loc2 = 0;
            while (loc2 < this._quickSellItemArr.length) 
            {
                loc1 = this._quickSellItemArr[loc2] as QuickSellGoodsItem;
                loc1.reset();
                ++loc2;
            }
            this._allPriceTxt.text = "";
            this._priceImg.bitmapData = null;
            return;
        }

        public updateQuickSellItem(arg1: SSeqMarketItem): void
        {
            var loc2=null;
            var loc3=0;
            if (!arg1) 
            {
                return;
            }
            var loc1=arg1.marketItems[0] as SMarketItem;
            loc3 = 0;
            while (loc3 < this._quickSellItemArr.length) 
            {
                loc2 = this._quickSellItemArr[loc3] as QuickSellGoodsItem;
                if (loc2.isSearch) 
                {
                    loc2.updateData(loc1);
                }
                ++loc3;
            }
            var loc4=0;
            var loc5=-1;
            loc3 = 0;
            while (loc3 < this._quickSellItemArr.length) 
            {
                loc2 = this._quickSellItemArr[loc3] as QuickSellGoodsItem;
                if (loc2.isSearch) 
                {
                    loc2.isSearch = false;
                }
                loc4 = loc4 + loc2.numSell * loc2.unitPrice;
                loc5 = loc2.unit;
                ++loc3;
            }
            this._allPriceTxt.text = loc4 + "";
            this._priceImg.bitmapData = null;
            if (loc4 > 0) 
            {
                if (loc5 != EPrictUnit._EPriceUnitCoin) 
                {
                    if (loc5 == EPrictUnit._EPriceUnitGold) 
                    {
                        this._priceImg.bitmapData = GlobalClass.getBitmapData(ImagesConst.Yuanbao_small);
                    }
                }
                else 
                {
                    this._priceImg.bitmapData = GlobalClass.getBitmapData(ImagesConst.Tongqian_small);
                }
            }
            return;
        }

        /* internal  */onNumStepperChangeHandler(arg1: DataEvent): void
        {
            var loc1=0;
            var loc2=null;
            var loc3=0;
            loc3 = 0;
            while (loc3 < this._quickSellItemArr.length) 
            {
                loc2 = this._quickSellItemArr[loc3] as QuickSellGoodsItem;
                loc1 = loc1 + loc2.numSell * loc2.unitPrice;
                ++loc3;
            }
            this._allPriceTxt.text = loc1 + "";
            return;
        }

        /* internal */ /* var */_allPriceTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_priceImg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_quickSellItemArr: Array<any>;
    }
